const axios = require('axios')

// 测试token
const token =
  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsInVzZXJuYW1lIjoidGVzdF91c2VyIiwiaWF0IjoxNzM2MjM5MDIzLCJleHAiOjE3MzYzMjU0MjN9.YMUVNIDFKdmwGJfE9Z8Yh_8KSYQE6EShpW-ykS0l7tc'

const baseURL = 'http://localhost:3000/api'

const headers = {
  Authorization: `Bearer ${token}`,
  'Content-Type': 'application/json'
}

async function testAPIs () {
  console.log('🧪 测试Payment API修复...\n')

  try {
    // 测试钱包信息API
    console.log('1. 测试钱包信息API...')
    const walletResponse = await axios.get(`${baseURL}/payment/wallet`, {
      headers
    })
    console.log('✅ 钱包API成功:', JSON.stringify(walletResponse.data, null, 2))
  } catch (error) {
    console.log('❌ 钱包API失败:', error.response?.data || error.message)
  }

  console.log('\n' + '='.repeat(50) + '\n')

  try {
    // 测试交易记录API
    console.log('2. 测试交易记录API...')
    const recordsResponse = await axios.get(
      `${baseURL}/payment/records?limit=20`,
      { headers }
    )
    console.log(
      '✅ 交易记录API成功:',
      JSON.stringify(recordsResponse.data, null, 2)
    )
  } catch (error) {
    console.log('❌ 交易记录API失败:', error.response?.data || error.message)
  }

  console.log('\n测试完成!')
}

testAPIs().catch(console.error)
